package cz.kfad.ofrss.synchronization;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.util.Calendar;

public class SyncScheduler extends BroadcastReceiver {

    public static final String TAG = SyncScheduler.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        AlarmManager alertService = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Log.i(TAG, "creating Sync alarm");

        Intent i = new Intent(context, StartSyncService.class);
        PendingIntent pending = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND, 30);

        alertService.setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 60 * 60 * 1000, pending);

    }

}
